import {
    post
} from "../../utils/request"
// const {
//     post
//   } = require("../../utils/request")

Page({

    /**
     * 页面的初始数据
     */
    data: {
        list: [],
        newslist: [],
        newslistDetial: [],
        pageNum:0,
        pageSize:10
    },
    // 下拉刷新
    
    onPullDownRefresh(){
 
            this.initData().then(res=>{
          
                wx.stopPullDownRefresh({
                  success: (res) => {},
                })
            })
    },

    //  封装的数组
    initData(){
     this.data.pageNum+=1
        let loadData=  post("https://showme.myhope365.com/api/cms/article/open/hot/list", {
            pageNum: this.data.pageNum,
            pageSize: 10,
        }).then(res => {
            console.log(res);
         
            this.setData({
                newslistDetial: res.data.rows
            })
            console.log(this.data.newslistDetial);

        })

        let indata2=post("https://showme.myhope365.com/api/cms/article/open/banner/list", {
            pageNum: 2,
            pageSize: 10
        }).then(res => {
            console.log(res);
            this.setData({
                list: res.data.rows
            })
        })
        let indata3=  post("https://showme.myhope365.com/api/cms/category/open/list", {
            pageNum: this.data.pageNum,
            pageSize: 10
        }).then(res => {
            console.log(res);
            this.setData({
                newslist: res.data.rows
            })
            console.log(this.data.newslist);

        })
        return Promise.all([loadData,indata2,indata3])
    },

    dianji(e) {
        console.log(e);

    },
    jump(e) {
        console.log(e);

        let b = e.currentTarget.dataset.item.articleId
        console.log(b);

        wx.navigateTo({
            url: '../newListdetail/newListdetail?articleid=' + b
        })
    },
    jumpDetail(e) {
        console.log(e);

        let b = e.currentTarget.dataset.item.articleId
        // console.log(b);
        wx.navigateTo({
            url: '../newListdetail/newListdetail?articleid=' + b
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        post("https://showme.myhope365.com/api/cms/article/open/banner/list", {
            pageNum: 1,
            pageSize: 10
        }).then(res => {
            console.log(res);
            this.setData({
                list: res.data.rows
            })
        })


        post("https://showme.myhope365.com/api/cms/category/open/list", {
            pageNum: this.data.pageNum,
            pageSize: 10
        }).then(res => {
            console.log(res);
            this.setData({
                newslist: res.data.rows
            })
            console.log(this.data.newslist);

        })

  
        post("https://showme.myhope365.com/api/cms/article/open/hot/list", {
            pageNum: 1,
            pageSize: 10,
        }).then(res => {
            console.log(res);
            this.setData({
                newslistDetial: res.data.rows
            })
            console.log(this.data.newslistDetial);

        })


    },


    // 下拉加载更多
    initUse(pageNum,pageSize){
        this.setData({
          loading:true
        })
       let loadData4 = post("https://showme.myhope365.com/api/cms/article/open/hot/list",{
          pageNum,
          pageSize,
         })
        .then(res=>{
          console.log(res.data.rows);
         setTimeout(() => {
          this.setData({
            newslistDetial: this.data.newslistDetial.concat(res.data.rows),
            loading:false
          })
         }, 3000);
         console.log(this.data.newslistDetial);
        })
        
        return Promise.all([loadData4])
      },
    

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */


    /**
     * 页面上拉触底事件的处理函数
     */
    
    onReachBottom: function () {
    
        this.data.pageNum+=1
        this.initUse(this.data.pageNum,this.data.pageSize).then(res=>{
            wx.stopPullDownRefresh({
              success: (res) => {},
            })
        })
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        return {
            title: "橘雎",
            imageUrl: "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1689053532,4230915864&fm=26&gp=0.jpg",
        }
    },
})